_G = {}

function _import(classFullName) {

    var index = classFullName.lastIndexOf(".")
    var length = classFullName.length
    var simpleName = classFullName.substring(index + 1, length)
    if(!_G[simpleName]){
        var classObject = Java.type(classFullName)

        if(simpleName.indexOf("[") !== -1 && simpleName.indexOf("]") !== -1) {
            simpleName = simpleName.replace(/\[|\]/g, "") + "Array"
            // simpleName = simpleName.substring(0,1).toUpperCase() + simpleName.substring(1);
        }

        eval(simpleName + " = classObject")
        _G[simpleName] = classObject
        //print("Java类型引用【 " + simpleName + " 】已载入全局，" + simpleName + " = _G[\"" + simpleName + "\"] = " + classObject)

    } else {
        //print("Java类型引用【 " + simpleName + " 】已存在于全局，" + simpleName + " = _G[\"" + simpleName + "\"] = " + _G[simpleName])
    }
    return _G[simpleName]

}

function _import_static(staticConstantOrStaticMethodFullName){
    var _this = this
    this.func = function(staticConstantOrStaticMethodFullName) {
        var index = staticConstantOrStaticMethodFullName.lastIndexOf(".")
        var length = staticConstantOrStaticMethodFullName.length
        var classFullName = staticConstantOrStaticMethodFullName.substring(0, index)
        var classObject = _import(classFullName)
        var staticConstantOrStaticMethodName = staticConstantOrStaticMethodFullName.substring(index+1, length)
        if(staticConstantOrStaticMethodName.indexOf("*") != -1) {
            _import("java.lang.reflect.Modifier")
            var fields = classObject.class.getDeclaredFields()

            for each (var field in fields) {
                if(Modifier.toString(field.getModifiers()).indexOf("public") != -1 && Modifier.toString(field.getModifiers()).indexOf("static") != -1) {
                    staticConstantOrStaticMethodName = field.getName()
                    if(!_G[staticConstantOrStaticMethodName]) {
                        var staticConstantOrStaticMethod = classObject[staticConstantOrStaticMethodName]
                        eval(staticConstantOrStaticMethodName + " = staticConstantOrStaticMethod")
                        _G[staticConstantOrStaticMethodName] = staticConstantOrStaticMethod
                        //print("Java静态导入引用【 " + staticConstantOrStaticMethodName + " 】已载入全局，" + staticConstantOrStaticMethodName + " = _G[\"" + staticConstantOrStaticMethodName + "\"] = " + staticConstantOrStaticMethod)
                    } else {
                        //print("Java静态引用【 " + staticConstantOrStaticMethodName + " 】已存在于全局，" + staticConstantOrStaticMethodName + " = _G[\"" + staticConstantOrStaticMethodName + "\"] = " + _G[staticConstantOrStaticMethodName])
                    }
                }
            }

            var methods = classObject.class.getDeclaredMethods()

            for each (var method in methods) {
                if(Modifier.toString(method.getModifiers()).indexOf("public") != -1 && Modifier.toString(method.getModifiers()).indexOf("static") != -1) {
                    staticConstantOrStaticMethodName = method.getName()
                    if(!_G[staticConstantOrStaticMethodName]) {
                        var staticConstantOrStaticMethod = classObject[staticConstantOrStaticMethodName]
                        eval(staticConstantOrStaticMethodName + " = staticConstantOrStaticMethod")
                        _G[staticConstantOrStaticMethodName] = staticConstantOrStaticMethod
                        //print("Java静态导入引用【 " + staticConstantOrStaticMethodName + " 】已载入全局，" + staticConstantOrStaticMethodName + " = _G[\"" + staticConstantOrStaticMethodName + "\"] = " + staticConstantOrStaticMethod)
                    } else {
                        //print("Java静态引用【 " + staticConstantOrStaticMethodName + " 】已存在于全局，" + staticConstantOrStaticMethodName + " = _G[\"" + staticConstantOrStaticMethodName + "\"] = " + _G[staticConstantOrStaticMethodName])
                    }
                }
            }
        } else {
            if(!_G[staticConstantOrStaticMethodName]) {
                var staticConstantOrStaticMethod = classObject[staticConstantOrStaticMethodName]
                eval(staticConstantOrStaticMethodName + " = staticConstantOrStaticMethod")
                _G[staticConstantOrStaticMethodName] = staticConstantOrStaticMethod
                //print("Java静态导入引用【 " + staticConstantOrStaticMethodName + " 】已载入全局，" + staticConstantOrStaticMethodName + " = _G[\"" + staticConstantOrStaticMethodName + "\"] = " + staticConstantOrStaticMethod)
            } else {
                //print("Java静态引用【 " + staticConstantOrStaticMethodName + " 】已存在于全局，" + staticConstantOrStaticMethodName + " = _G[\"" + staticConstantOrStaticMethodName + "\"] = " + _G[staticConstantOrStaticMethodName])
            }
            _this.sourceName = staticConstantOrStaticMethodName

        }
        return this
    };
    this._alias = function(alias) {
        var staticConstantOrStaticMethod = _G[_this.sourceName]
        _G[alias] = staticConstantOrStaticMethod
        _G[_this.sourceName] = null
        eval(alias + " = staticConstantOrStaticMethod; " + _this.sourceName + " = null;")
        //print("源名称【 " + _this.sourceName + " 】已修改为【 " + alias + " 】= _G[\"" + alias + "\"] = " + staticConstantOrStaticMethod + ", _G[\"" + _this.sourceName + "\"] = " + _G[_this.sourceName])
        return this
    }
    return this.func(staticConstantOrStaticMethodFullName)
}

function _new(javaType){
    return new JavaObjectWrap().newInstance(javaType)
}

function JavaObjectWrap(){
    var _this = this
    this.instance = null
    this.newInstance = function(javaType){
        _this.type = javaType;
        _this.instance = javaType === null ? null : new javaType()
        return _this.instance
    }
}

function _typeof(javaType) {
    return javaType.class.getName()
}

function _gof(javaTypeSimpleName){
    return _G[javaTypeSimpleName]
}